package com.example.yunpicturebackend.exception;


import com.example.yunpicturebackend.common.BaseResponse;
import com.example.yunpicturebackend.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Yan.z.h
 * @version 1.0
 */
@RestControllerAdvice
@Slf4j
public class GlobalEceptionHandler {

@ExceptionHandler(BusinessException.class)
    public BaseResponse bussinessExceptionHandler(BusinessException e){
    log.error(e.getMessage(),e);
    return ResultUtils.error(e.getCode(), e.getMessage());

   }

   @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeExceptionHandler(RuntimeException e){
    log.error("RuntimeExceeption",e);
    return ResultUtils.error(ErrorCode.SYSTEM_ERROR);
   }
}
